﻿Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Configuration

<WebService(Namespace:="http://www.mydomainname.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class AutoComplete
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    <ScriptMethod()> _
    Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
        Dim conn As New DatabaseCommon
        Dim connection As New SqlConnection(conn.ConnectionString)
        Dim cmd As New SqlCommand("SELECT DISTINCT TOP(@nrows) qTitle FROM [Question] WHERE qTitle like @term", connection)
        cmd.Parameters.AddWithValue("@nrows", count)
        cmd.Parameters.AddWithValue("@term", prefixText & "%")
        Dim suggestions As New List(Of String)()
        connection.Open()
        Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            While dr.Read()
                suggestions.Add(dr(0).ToString())
            End While
        End Using
        Return suggestions.ToArray()
    End Function

    <WebMethod()> _
    <ScriptMethod()> _
    Public Function GetCompletionList1(ByVal prefixText As String, ByVal count As Integer) As String()
        Dim conn As New DatabaseCommon
        Dim connection As New SqlConnection(conn.ConnectionString)
        Dim cmd As New SqlCommand("SELECT DISTINCT TOP(@nrows) aAnswer FROM [Answer] WHERE aAnswer like @term", connection)
        cmd.Parameters.AddWithValue("@nrows", count)
        cmd.Parameters.AddWithValue("@term", prefixText & "%")
        Dim suggestions As New List(Of String)()
        connection.Open()
        Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            While dr.Read()
                suggestions.Add(dr(0).ToString())
            End While
        End Using
        Return suggestions.ToArray()
    End Function

End Class
